package cn.fscode.code.generator.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author shenguangyang
 */
public class TableUtils {
    /**
     * 从字符串中提取连续英文
     * <p>
     * 比如: 输入字符串 （23423xxx）哈哈哈a_good_hello., 会匹配到两个分别为
     * xxx, a_good_hello
     * </p>
     */
    private static final String TABLE_NAME_REG = "[a-zA-Z_]+('?[a-zA-Z])?";
    private static final Pattern tableNamePattern = Pattern.compile(TABLE_NAME_REG);

    /**
     * 从字符串中提取表名, 要求表名放到最后
     * @param str 字符串, eg: （23423xxx）哈哈哈a_good_hello.
     * @return 返回表名, a_good_hello
     */
    public static String getTableName(String str) {
        Matcher m = tableNamePattern.matcher(str);
        String tableName = "";
        while (m.find()) {
            tableName = m.group();
        }
        return tableName;
    }
}
